package com.zb.spring5.configuration;

import com.zb.spring5.ioc.inteface.MessageProvider;
import com.zb.spring5.ioc.inteface.MessageRender;
import com.zb.spring5.ioc.inteface.impl.ConfigurableMessageProvider;
import com.zb.spring5.ioc.inteface.impl.StandardOutMessageRender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;

/**
 * 使用属性文件。
 */
@Configuration
@PropertySource(value = "classpath:message.properties")
public class AppConfigOne {
    @Autowired
    Environment env;

    @Bean
    @Lazy
    public MessageProvider messageProvider(){

        return  new ConfigurableMessageProvider(env.getProperty("message"));
    }
    @Bean(name = "messageRender")
    @Scope(value = "prototype")
    @DependsOn(value = "messageProvider")
    public MessageRender messageRender() {
        StandardOutMessageRender render = new StandardOutMessageRender();
        render.setMessageProvider(messageProvider());
        return render;
    }
}
